<?php

abstract class AbstractTableCreator {

    protected $arrAccessors = array();
    public function __construct() {
        $this->arrAccessors = $this->getAccessorsArray();
    }

    abstract protected function getAccessorsArray();

    public function test() {}

    public final function recreateTable() {

        $harrSavedRecords = array();

        foreach ($this->arrAccessors as $key => $oAccessor) {
            $harrSavedRecords[$key] = $oAccessor->isTableExists() ?
                $oAccessor->getRecordsAsHash() :
                array();
        }

        $this->recreateTableNonSafe();

        foreach ($this->arrAccessors as $oAccessor) {
            if ($oAccessor->isTableExists()) {
                $oAccessor->dropTable();
            }
            $oAccessor->createStructure();
        }

        foreach ($this->arrAccessors as $key => $oAccessor) {
            $oAccessor->insertRecordsArray($harrSavedRecords[$key]);
        }
    }

    public final function recreateTableNonSafe() {

        foreach ($this->arrAccessors as $oAccessor) {
            if ($oAccessor->isTableExists()) {
                $oAccessor->dropTable();
            }
            $oAccessor->createStructure();
        }
    }

    protected function showStatus() {
        foreach ($this->arrAccessors as $oAccessor) {
            echo get_class($oAccessor) . "\n";
            echo 'number: ' . $oAccessor->getCount() . "\n";
            echo 'all: ' . print_r($oAccessor->getRecordsAsHash(), 1) . "\n";
        }
    }
}

?>